package com.caiyouxi.finance.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.finance.mapper.CouponTypeMapper;
import com.caiyouxi.finance.model.CouponType;
import com.caiyouxi.finance.service.CouponTypeServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CouponTypeServicesImpl extends BaseService implements CouponTypeServices{
    @Autowired
    private CouponTypeMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData select_coupon_type(CouponType bean) {
        return success(mapper.select_coupon_type(bean.getId()));
    }

    @Override
    public ResData add_coupon_type(CouponType bean) {
        return success(mapper.add_coupon_type(bean));
    }

    @Override
    public ResData update_coupon_type(CouponType bean) {
        return success(mapper.update_coupon_type(bean));
    }

    @Override
    public ResData delete_coupon_type(CouponType bean) {
        return success(mapper.delete_coupon_type(bean));
    }

    @Override
    public ResData coupon_type_list(CouponType bean) {
        QueryParams pageList = new QueryParams();
        if(bean.getPage_size() == 0){
            bean.setPage_size(Integer.parseInt(redisService.get("sys.pagesize").toString()));
        }
        pageList.setList(mapper.coupon_type_list(bean));
        pageList.setTotal(mapper.coupon_type_count(bean));
        return success(pageList);
    }
}
